package com.mes.spc.rule;

import java.util.ArrayList;
import java.util.List;

public class SpcRule5 extends SPCCommandbase {
    public int id=5;
    public int warningCount=3;
    public String title="规则5";
    public String description="连续3点中有2点落在中心线同一侧的2倍sigma区以外";
    private List<Double> old = new ArrayList<Double>();
    private int count;
    public boolean excute(double data, double usl, double lsl, double ucl, double lcl, double standard)
    {
        double bu =standard+ ucl/ 3 * 2;
        double bl =standard+ lcl / 3 * 2;
        int u = 0;
        int l = 0;
        old.add(data);
        count++;
        if (count > 3)
        {
            count--;
            old.remove(0);
        }
        for(double o : old)
        {
            if (o > bu)
                u++;
            else if (o < bl)
                l++;
        }
        if (u >= 2 || l >= 2)
            return true;
        return false;
    }

    public int getId() {
        return id;
    }

    public int getWarningCount() {
        return warningCount;
    }

    public String getTitle() {
        return title;
    }

    public String getDescription() {
        return description;
    }
}
